/**
 * 获取文件类型
 * @param {*} filename 
 */
const getFileType = (filename) =>{
    const startIndex = filename.lastIndexOf('.')
    if (startIndex !== -1) {
      return filename.substring(startIndex + 1, filename.length).toLowerCase()
    } else {
      return ''
    }
} 
/**
 * 获取格式化文件大小
 * @param {*} size
 * @returns {string}
 */
const formatFileSize = (size) =>{
    const B = 1024
    const KB = Math.pow(1024, 2)
    const MB = Math.pow(1024, 3)
    const GB = Math.pow(1024, 4)
    if (!size) {
      return '_'
    } else if (size < KB) {
      return (size / B).toFixed(0) + 'KB'
    } else if (size < MB) {
      return (size / KB).toFixed(1) + 'MB'
    } else if (size < GB) {
      return (size / MB).toFixed(2) + 'GB'
    } else {
      return (size / GB).toFixed(3) + 'TB'
    }
}

/**
 * 格式化文件大小 单位：B、KB、MB、GB
 * @param {*} value 
 */
const renderSize = value => {
    if (null == value || value == '') {
      return "0 B"
    }
    var unitArr = new Array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
    var index = 0
    var srcsize = parseFloat(value)
    index = Math.floor(Math.log(srcsize) / Math.log(1024))
    var size = srcsize / Math.pow(1024, index)
    size = size.toFixed(2)
    if (unitArr[index]) {
      return size + unitArr[index]
    }
    return '文件太大'
}